package it.ap.sa.core.dao.generator;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Order;

/**
 * @author Alessandro Paolillo
 */
public abstract class GenericCriteriaGenerator<F> implements ICriteriaGenerator {
	
	private List<Order> ordinamento = new ArrayList<Order>();
	private F filter;

	public abstract Criteria buildCriteria(Session session, F filter);

	@Override
	public Criteria build(Session session) throws Exception {
		return buildCriteria(session, filter);
	}

	public Criteria addOrders(Criteria criteria) {
		if (ordinamento != null && ordinamento.size() > 0) {
			for (Order ordine : ordinamento) {
				criteria.addOrder(ordine);
			}
		}
		return criteria;
	}

	public void addOrder(Order order) {
		this.ordinamento.add(order);
	}

	public List<Order> getOrdinamento() {
		return ordinamento;
	}

	public void setOrdinamento(List<Order> ordinamento) {
		this.ordinamento = ordinamento;
	}
}
